/*
 * Route.cpp
 *
 *  Created on: Nov 1, 2009
 *      Author: jbarreneche
 */

#include "Route.h"

Route::Route(MapPoint &start) {
	this->points.add(0,new MapPoint(start));
	this->totalCost = 0.0;
}
Route::~Route() {
	while (!points.isEmpty()) {
		delete points.removeFirst();
	}
}

void Route::build(RoadSegment* segment, MapPoint &to, double cost) {
	this->points.append(new MapPoint(to));
	this->segments.append(segment);
	this->totalCost += cost;
}

RoadSegment* Route::popSegment()  throw(EndOfRouteException){
	if (this->isEmpty()) throw EndOfRouteException();
	delete this->points.removeFirst();
	return this->segments.removeFirst();
}

RoadSegment* Route::currentSegment() throw(EndOfRouteException){
	if (this->isEmpty()) throw EndOfRouteException();
	return this->segments.get(0);
}

MapPoint Route::headingTo() throw(EndOfRouteException){
	if (this->isEmpty()) throw EndOfRouteException();
	return *this->points.get(1);
}

MapPoint Route::currentPoint() {
	return *this->points.get(0);
}
